package com.woniuxy.aspect;

import com.woniuxy.entity.User;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
/*定义切面类*/
public class AspectJava {
    /*前置通知*/
    public void myBefore(JoinPoint joinPoint){
        System.out.println("前置通知：事务开启.....");
        System.out.println("获取目标类"+joinPoint.getTarget());
        System.out.print(",被织入增强的目标方法是："+joinPoint.getSignature().getName());
    }
    /*后置通知*/
    public void myAfterReturning(JoinPoint joinPoint){
        System.out.println("后置通知：模拟事务的提交...");
        System.out.print(",被织入增强的目标方法是："+joinPoint.getSignature().getName());
    }
    /*环绕通知*/
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知开启");
        //可以获取入参
        Object[] args = proceedingJoinPoint.getArgs();
        args[0] = 1;
        User user = (User) proceedingJoinPoint.proceed(args);
        user.setName("查数据。。。。。");
        return user;
    }
    /*异常通知*/
    public void myAfterThrowing(JoinPoint joinPoint ,Throwable e){
        System.out.println("抛出异常"+e.getMessage());
    }
    /*最终通知*/
    public void myAfter(){
        System.out.println("最终通知执行");
    }
}
